<?php
session_start();
//require_once("include/authen.php");
	require_once("class/m_main.php");
	$id=$_GET['i'];
	$m=new M_main();
	$arrList = $m->getTransaction($id); 
?>
<table width="320px"cellspacing="0" cellpadding="2" border="0">
<tr>
	<td colspan="3" align='center' style="font-size:11;font-family:tahoma">Kongju Clinic Co., Ltd.</td>
</tr>
 
<tr>
	<td colspan="3" align='left' style="font-size:11;font-family:tahoma">ที่อยู่ :  &nbsp;อาคาร เอส.เค.ดี มั่นคง กรุ๊ฟ เลขที่ 213/1-2 ชั้น 3 ถ.รัชดาภิเษก ห้วยขวาง ข.สุทธิสาร กทม</td>
</tr>
<tr>
	<td colspan="3">
		<table width="100%">
		<tr>
			<td  width="50%" align='left' style="font-size:11;font-family:tahoma">Tax#: &nbsp;<?php echo $arrList['Tax']?></td>
			<td align='right' style="font-size:11;font-family:tahoma">Date:&nbsp;<?php echo $arrList['SaleDate']?></td>
		</tr>
		</table>
	</td>
</tr>
<tr>
	<td colspan="3" align='left' style="font-size:11;font-family:tahoma">หมายเลขใบเสร็จ: <?php echo str_repeat('0', 5 - strlen($arrList['BillNo']) ) .$arrList['BillNo']?></td>
</tr>
<tr>
	<td colspan="3" align='center' style="font-size:12;font-family:tahoma;font-weight:bold;padding-top:5px">ใบเสร็จรับเงิน/ ใบกำกับภาษีอย่างย่อ</td>
</tr>
<tr>
	<td colspan="3" align='center' style="font-size:10">====================================================</td>
</tr>
<tr>
	<td colspan="3" align='center' style="font-size:10">&nbsp;</td>
</tr>
<?php 
	$detail = $arrList['detail'];
	$payment = $arrList['payment']; 
	foreach ($detail as $h){
?>
<tr>
	<td align='left' width="10"  style="font-size:11;font-family:tahoma;padding-left:3px;"><?php echo $h['Amount']?></td>
	<td align='left' width="280" style="font-size:11;font-family:tahoma;padding-left:0px;"><?php echo $h['ProductName']?></td>
	<td align='right'   style="font-size:11;font-family:tahoma"><?php echo $h['Total']?></td>
</tr>
<?php 	
	}
?>
 
<tr>
	<td colspan="3" align='center' style="font-size:10">&nbsp;</td>
</tr>
<tr>
	<td colspan="3" align='center' style="font-size:10">====================================================</td>
</tr>
<tr>
	<td colspan="2" align='left' style="font-size:11;font-family:tahoma;padding-left:2px;font-weight:bold;">Total :</td>
	<td align='right' style="font-size:11;font-family:tahoma;"><?php echo number_format( $arrList['Amount'],2,'.',',')?></td>
</tr>
<?php  if ($arrList['IsExtraDiscount']<>0){
		$spDis = $arrList['specailDiscount'];
		 
		if ($spDis['Type']==1){
			$col='Premium :';
			$amt=$spDis['DiscountType'];
		}else{
			$col='Special discount :';
			$arrList['Discount']=$arrList['Discount']-$spDis['DiscountType'];
			$amt=number_format( $spDis['DiscountType'],2,'.',',');
		}
	}
?>
<tr>
	<td colspan="2" align='left' style="font-size:11;font-family:tahoma;padding-left:2px;;font-weight:bold;">Discount :</td>
	<td align='right' style="font-size:11;font-family:tahoma;"><?php echo number_format( $arrList['Discount'],2,'.',',')?></td>
</tr>
<?php  if ($arrList['IsExtraDiscount']<>0){?>
<tr>
	<td colspan="2" align='left' style="font-size:11;font-family:tahoma;padding-left:2px;;font-weight:bold;"><?php echo $col?></td>
	<td align='right' style="font-size:11;font-family:tahoma;"><?php echo $amt?></td>
</tr>
<?php }?>
<tr>
	<td colspan="2" align='left' style="font-size:11;font-family:tahoma;padding-left:2px;;font-weight:bold;">Total Net :</td>
	<td align='right' style="font-size:11;font-family:tahoma;"><?php echo number_format($arrList['TotalNet'],2,'.',',')?></td>
</tr>
<tr>
	<td colspan="3" align='center' style="font-size:10">.....................................................................................................</td>
</tr>
<?php 
$payamttotal=0;
foreach ($payment as $p){
	$payamttotal +=$p['PaymentAmount'];
	if ($p['PaymentType']==1){
		$paytype="Cash:";
	}else if ($p['PaymentType']==2){
		$paytype="Credit:";
	}else {
		$paytype="Smart purse:";
	}
?>
<tr>
	<td colspan="2" align='left' style="font-size:11;font-family:tahoma;padding-left:2px;;font-weight:bold;"><?php echo $paytype;?></td>
	<td align='right' style="font-size:11;font-family:tahoma;"><?php echo number_format($p['PaymentAmount'],2,'.',',')?></td>
</tr>	
<?php
$remain=$arrList['course'];
}
?>
<tr>
	<td colspan="2" align='left' style="font-size:11;font-family:tahoma;padding-left:2px;;font-weight:bold;">Remain Amount</td>
	<td align='right' style="font-size:11;font-family:tahoma;"><?php echo number_format($arrList['TotalNet'] - $payamttotal,2,'.',',')?></td>
</tr>

<tr>
	<td colspan="3" align='center' style="height:25px;">&nbsp;</td>
</tr>
<?php
  if ($arrList['CustID'] !='0'){
?>
<tr>
	<td colspan="3" align='left'  style="font-size:11;font-family:tahoma;padding-left:2px;;font-weight:normal;"><b>ชื่อลูกค้า :</b> <?php echo $arrList['FirstName'] .' '. $arrList['LastName'] ?></td>
</tr>
<?php if ($remain['remainAmt']!='0') {?>
<tr>
	<td colspan="2" align='left' style="font-size:11;font-family:tahoma;padding-left:2px;;font-weight:normal;"><b>มียอดค้างชำระจำนวน : </b></td>
	<td align='right' style="font-size:11;font-family:tahoma;"><?php echo number_format($remain['remainAmt'],2,'.',',') ?></td>
</tr>
<?php } 
 if ($remain['serviceCnt']!='0') {
	 foreach ($remain['servicelst'] as $val){
 ?>
<tr>
	<td colspan="3" align='left' style="font-size:11;font-family:tahoma;padding-left:2px;;font-weight:normal;"><b>คอร์ส : </b><?php echo $val['ProductName'] ?></td>
</tr>
<tr>
	<td colspan="3" align='center' >
	<table style='width:100%'>
		<tr>
			<td width='50%' align='left' style="font-size:11;font-family:tahoma;padding-left:2px;;font-weight:normal;"><b>จำนวนคงเหลือ : </b><?php echo $val['Remain'] ?> ครั้ง</td>
			<td align='right' style="font-size:11;font-family:tahoma;padding-left:2px;;font-weight:normal;"><b>หมดอายุ : </b><?php echo $val['ExpireDate'] ?></td>
		</tr>
	</table>
	</td>
</tr>
<?php }?>

<?php }?>
<?php }?>
<tr>
	<td colspan="3" align='center' style="height:20px;">&nbsp;</td>
</tr>
<tr>
	<td colspan="3" align='center' style="font-size:10;font-family:tahoma;padding-left:2px;;font-weight:normal;color:#333;">**สินค้าซื้อแล้วไม่รับคืน</td>
</tr>
</table>
<?php 
 echo "<script>window.print();</script>";
?>